<template>
  <div class='search'>
    <f-form ref='form' :action='api.hyOrderDetails.calculate' :form-key='this.formItem.orderDetailsId'>
      <f-form-item label='发货方式' type='radio' name='sendType' :disabled='true' dataType='number' :data='api.busCommon.sendType' :value.sync='formItem.sendType' />
      <f-form-item label='购方资信' type='radio' name='customBondType' :disabled='true' dataType='number' :data='api.busCommon.customBondType' :value.sync='formItem.customBondType' v-if='formItem.sendType==3' />
      <f-form-item label='数量' type='number' :required='true' data-type='number' :disabled='true' :min='-5000' name='saleNum' :value='formItem.saleNum' />
      <f-form-item label='销售价' type='number' :required='true' data-type='number' :disabled='true' :precision='4' name='salePrice' :value='formItem.salePrice' />
      <f-form-item label='销售金额' type='number' :required='true' data-type='number' :disabled='true' :precision='2' name='saleAmount' :value='formItem.saleAmount' />
      <f-form-item label='成本价' type='number' :required='true' :precision='4' data-type='number' name='costPrice' :value='formItem.costPrice' />
      <f-form-item label='成本金额' type='number' :required='true' :precision='2' data-type='number' :disabled='true' name='costAmount' :value='formItem.costAmount' />
      <f-form-item label='自定义政策' type='radio' extra='特殊政策的订单启用后自定义政策后可在核算时自定义结算政策'  name='customPolicy'  dataType='number' :data='api.common.status' :value.sync='formItem.customPolicy'/>
      <f-form-item label='底价公式' extra='按自定义公式计算资保金底价' placeholder='请选择底价公式' name='customFloorAmountFormula' :readOnly='formItem.disabled'  :value.sync='formItem.customFloorAmountFormula' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openFormulaModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label='政策说明' name='policyRemark' :value='formItem.policyRemark' />
    </f-form>
    <select-formula-modal ref='formulaModal' @onSelectChange='onSelectFormulaChange'></select-formula-modal>
  </div>
</template>
<script>
import api from "../../js/api"
import SelectFormulaModal from "../../components/select_formula_modal"
export default {
  name: "HyOrderCalculateTab1",
  props: {},
  data() {
    return {
      refs: this.$refs,
      loadDept: false,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      formItem: this.getFormItem(),
      disabled: false,
      params1: {
        formulaType: 1
      }
    }
  },
  methods: {
    getFormItem() {
      return {
        orderId: "",
        sendType: "",
        customBondType: 0,
        customFloorAmountFormula: ""
      }
    },
    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.orderDetailsId) {
        if (data.orderState == 2) {
          this.disabled = true
        }
        this.http.get(this, {
          url: this.api.hyOrderDetails.get,
          params: {
            orderDetailsId: data.orderDetailsId,
            handlerName: "hyCalCulateTab1GetHandler"
          },
          success: function(me, data) {
            me.formItem = data
          }
        })

      }
    },
    /**
     * 选择底价公式
     */
    openFormulaModal() {
      this.$refs["formulaModal"].open({
        formulaType: 1
      })
    },
    /**
     * 公式选择回调
     */
    onSelectFormulaChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "customFloorAmountFormula": selectedRows[0].formulaContent })
      this.formItem.customFloorAmountFormula= selectedRows[0].formulaContent;
    },

    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit(this.formItem, callback)
    }
  },
  mounted() {

  },
  created() {
  },
  components: {SelectFormulaModal}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
